package com.whu.helpluojia.controller;

import com.whu.helpluojia.common.BaseContext;
import com.whu.helpluojia.common.R;
import com.whu.helpluojia.domain.HelpInformation;
import com.whu.helpluojia.domain.MyPublish;
import com.whu.helpluojia.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@Slf4j
@RestController
@RequestMapping("/publishment")
public class PublishmentController {

    @Autowired
    BagManService bagManService;

    @Autowired
    FindService findService;

    @Autowired
    LostAndFoundService lostAndFoundService;

    @Autowired
    SupplyService supplyService;

    @Autowired
    ConsultService consultService;

    @GetMapping("/{id}/{category}")
    public MyPublish getPublishDetail(@PathVariable Long id,@PathVariable int category){

        Long userId=BaseContext.getCurrentId();

        log.info(String.valueOf(category));

        MyPublish myPublish=new MyPublish();

        switch (category){
            case 1:
                myPublish=bagManService.getBagmanDetail(id,userId);
                break;
            case 2:
                myPublish=supplyService.getSupplyDetail(id,userId);
                break;
            case 3:
                myPublish=findService.getFindDetail(id,userId);
                break;
            case 4:
                myPublish=lostAndFoundService.getLafDetail(id,userId);
                break;
            case 5:
                myPublish=consultService.getConsultDetail(id,userId);
                break;
            default:
                break;

        }

        return myPublish;
    }

    @PostMapping()
    public void solutePublish(@RequestBody HelpInformation helpInformation){
        if(Objects.equals(helpInformation.getCategory(), "求跑腿")){
            bagManService.solute(helpInformation.getId());
        } else if (Objects.equals(helpInformation.getCategory(), "寻物启事")) {
            findService.solute(helpInformation.getId());
        } else if (Objects.equals(helpInformation.getCategory(), "失物招领")) {
            lostAndFoundService.solute(helpInformation.getId());
        } else if (Objects.equals(helpInformation.getCategory(), "物品供需")) {
            supplyService.solute(helpInformation.getId());
        }
    }

}
